﻿/*******************************************************************************
 * 系统变量
 * 
 * @type
 */
App = {
	models : {
		USER : 'User',
		USER_LIST : 'UserList',
		MESSAGE : 'message'
	},
	views : {
		USER : '',
		HOME : 'Home',
		MESSAGE_MANAGER : 'MessageManager',
		USER_MANAGER : 'UserManager'
	},
	controllers : {
		VIEW : 'View',
		HOME : 'Home',
		MESSAGE_MANAGER : 'MessageManager',
		USER_MANAGER : 'UserManager',
		OAUTH :'OAuth'
	},
	stores : {
		USER : 'UserStore',
		TIMELINE : 'timeline'
	},
	API : {
		sina : {
			oauth:{
				secret:{
					consumerKey:'81023575',
					consumerSecret:'6d5bf333eca2426d0648bc148e112724',
					token:null,
					secret:null
				},
				action:{
					request:'http://api.t.sina.com.cn/oauth/request_token',
					authorize:'http://api.t.sina.com.cn/oauth/authorize',
					access:'http://api.t.sina.com.cn/oauth/access_token',
					login:'http://api.t.sina.com.cn/oauth/login.jsp'
				},
				method:'GET',
				version:'1.0',
				callback:'http://localhost:8080/yoha/proxy.html',
				signatureMethod:'HMAC-SHA1'
			}
		},
		tencent : {
			oauth:{
				secret:{
					consumerKey:'43ff2b2370334df793560d2d9e29a5c4',
					consumerSecret:'974dc3ded62d44364cb7035d6b1016e3',
					token:null,
					secret:null
				},
				action:{
					request:'https://open.t.qq.com/cgi-bin/request_token',
					authorize:'https://open.t.qq.com/cgi-bin/authorize',
					access:'https://open.t.qq.com/cgi-bin/access_token'
				},
				method:'GET',
				version:'1.0',
				callback:'null'||'http://localhost:8080/yoha/proxy.html',
				signatureMethod:'HMAC-SHA1'
			}
		},
		netease : {
			key:'',
			secret:'',
			oauth:{
				request:'',	
				access:''
			}
		},
		sohu : {
			key:'',
			secret:'',
			oauth:{
				request:'',
				access:''
			}
		}
	}
};
/*******************************************************************************
 * 设置系统默认设置
 */
(function() {
	// toolbar 默认值
	var toolbarSettings = Ext.Toolbar.prototype;
	toolbarSettings.scroll = 'horizontal';
	toolbarSettings.defaults = {
		iconMask : true,
		ui : 'plain'
	};
	toolbarSettings.layout = {
		pack : 'center'
	};
	Ext.Viewport.onTouchStartCapturing = function(e) {
        if (!Ext.currentlyFocusedField && Ext.is.Phone) {
            this.scrollToTop();
        }
    }
})();
// 应用程序
Ext.ns('Microblogging');
Microblogging.unrealizedMsg = function(){
	Ext.Msg.alert('提示','对不起该微薄接口尚未实现，请您继续关注我们的产品。');
}
// 注册应用程序
Ext.regApplication({
			id : 'Microblogging',
			defaultUrl : 'home',
			views : new Ext.util.MixedCollection(),
			addView : function() {
				if (typeof arguments[1] == 'string') {
					arguments[1] = {
						xtype : arguments[1]
					};
				}
				return this.views.add.apply(this.views, arguments);
			},
			getView : function(key) {
				return this.views.get.call(this.views, key);
			},
			insertView : function() {
				if (typeof arguments[2] == 'string') {
					arguments[2] = {
						xtype : arguments[2]
					};
				}
				return this.views.insert.apply(this.views, arguments);
			},
			launch : function() {
				// application start
				this.viewport = new Microblogging.Viewport({
							application : this
						});
				var starting = Ext.get('starting');
				Ext.defer(function() {
	                starting.addCls('fadeout');
	                Ext.defer(function() {
	                    starting.remove();
	                }, 500);
	            }, 1500);
			}
		});
/*******************************************************************************
 * 获取应用程序
 * 
 * @appName 
 *            
 * @return {}
 */
Microblogging.getApplication = function(appName) {
	return Ext.ApplicationManager.get(appName || 'Microblogging');
};
/*******************************************************************************
 * 对指定应用添加视图
 * 
 * @index
 * @key
 * @value
 * @appName
 * 
 * @return {}
 */
Microblogging.addView = function() {
	var appName = arguments.length === 4 ? arguments[4] : arguments[3], app = Microblogging
			.getApplication(appName);
	if (!app || !app.insertView || !app.addView) {
		return null;
	}
	return typeof arguments[0] == 'number' ? app.insertView.apply(app,
			arguments) : app.addView.apply(app, arguments);
};
/*******************************************************************************
 * 获取指定视图
 * 
 * @param {}
 *            key
 * @param {}
 *            appName
 * @return {}
 */
Microblogging.getView = function(key, appName) {
	var app = Microblogging.getApplication(appName);
	return app && app.getView ? app.getView.call(app, key) : null;
};